/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once

#include "../../S_Physics.h"

#undef mjUSEDOUBLE;

#include <mujoco/mujoco.h>
#include <mujoco/mjxmacro.h>



struct S_PhysicsMujoco : public S_Physics {

	mjModel*	m_模型;
	mjData*		m_模拟数据;

	std::vector<S_物理体*>	m_Body;
	std::set<S_物理体*>		m_预备构建物理体;

	static C_StrKey分配器	g_名称生成器;

	S_PhysicsMujoco(std::wstring name = L"Mujoco_model");
	~S_PhysicsMujoco();

	void	f_Update();
	void	f_重置变换(bool 解算 = false);
	//void	f_构建场景XML();
};





S_物理体* f_PhyMujoco_场景物理体();

S_Physics* f_PhysMujoco_创建物理引擎();

void f_PhysMujoco_重构(S_PhysicsMujoco* phy, const std::string& path);

void f_PhysMujoco_销毁物理引擎(S_Physics* phy);

void f_PhyMujoco_解算(S_PhysicsMujoco* phy, float32 时间步进);

void f_PhyMujoco_添加物理体(S_PhysicsMujoco* 解算器, std::vector<S_物理体*>& body);
void f_PhyMujoco_构建物理体(S_PhysicsMujoco* 解算器, S_PhyBodyArray* body);

void f_PhyMujoco_重构(S_PhysicsMujoco* 解算器);
Inline void f_PhyMujoco_重置运动(S_PhysicsMujoco* mj) {
	if(mj->m_模型) mj_resetData(mj->m_模型, mj->m_模拟数据);
}

std::vector<S_物理体*> f_PhyMujoco_get几何图形(S_PhysicsMujoco* 解算器, E_物理几何体类型 几何类型);

void f_PhyMujoco_构建内部几何体填充到物体(S_PhysicsMujoco* 解算器, std::vector<S_物理体*>& Body);

void f_PhyMujoco_施加力(S_PhysicsMujoco* 解算器, const S_施加物理力& 互交);
void f_PhyMujoco_施加力(S_PhysicsMujoco* 解算器, const S_施加物理力& f, E_施加力类型 type);

uint32 f_PhyMujoco_get肌腱数量(S_PhysicsMujoco* mj);
void f_PhyMujoco_set肌腱力度(S_PhysicsMujoco* mj, float32* 力度, int32 id);
void f_PhyMujoco_构建肌腱物体可视(S_PhysicsMujoco* mj, S_物体* Body);

void f_PhyMujoco_更新物体变换(S_PhysicsMujoco* 解算器);

